GraphQL and SpaceQL
Smart DIH includes embedded GraphQL API Gateway functionality.
The GraphQL API Gateway service allows to query XAP spaces using GraphQL syntax.
The service detects all Spaces and corresponding types that exist in each Space. It then auto-generates GraphQL functions that can be used to easily query the Space and retrieve faster results in comparison to using the equivalent SQL queries.
You can query the GraphQL service through SpaceQL, or using the DIHCTL application.
Enable GraphQL
To enable GraphQL, add the following global option when installing Smart DIH:
--set global.graphql.enabled=true
SpaceQL
SpaceQL is a GraphQL user interface, integrated in the DIH SpaceDeck. It allows to perform interactive GraphQL queries.
For an overview of the SpaceQL menu in SpaceDeck, refer to the SpaceDeck - SpaceQL page.
Configure Relations Between GraphQL Schemas
You can configure relations between GraphQL schemas:
-
Through SpaceQL, as above.
-
Using the DIHCTL application, for example:
This yaml file contains relations between two tables - customers and orders, and orders and products:
graphqlTypes: - name: "CUSTOMERS" space: "demo" relations: - name: "orders" referencedType: "ORDERS" referencedTypeSpace: "demo" usingId: false foreignKeyColumn: "CUSTOMER_ID" referencedTypeColumn: "CUSTOMER_ID" - name: "ORDERS" space: "demo" relations: - name: "product" referencedType: "PRODUCTS" referencedTypeSpace: "demo" usingId: true foreignKeyColumn: "PRODUCT_ID"
This file can be applied and the two relations can be created using the following command:
./dihctl -e YOUR_ENV apply -f PATH_TO_FILE.yaml
Export Existing Relations
You can export existing relations for all Spaces in a cluster:
-
Through SpaceQL, as above.
-
Using the DIHCTL application, by performing the following command:
./dihctl -e YOUR_ENV export relations -o OUTPUT_FILE_NAME.yaml
Query the GraphQL Service Using DIHCTL
Example 1: Querying a Customer
This example shows querying a customer after creating relevant relations that will hold all relevant data regarding the customer's orders and corresponding order products.
query customers($customerId: BigDecimal!) { demo_customersById(CUSTOMER_ID: $customerId) { COMMENTS CREDIT_LIMIT CUSTOMER_CITY CUSTOMER_COUNTRY CUSTOMER_FIRST_NAME CUSTOMER_ID CUSTOMER_LAST_NAME CUSTOMER_STREET CUSTOMER_ZIPCODE DATE_OF_BIRTH EMAIL GENDER INCOME_LEVEL LAST_UPDATE PHONE_NUMBER ZZ_META_DI_TIMESTAMP orders { CARD_TYPE CUSTOMER_ID LAST_UPDATE ORDER_DATE ORDER_ID ORDER_NOTES ORDER_STATUS ORDER_TOTAL PRODUCT_ID ZZ_META_DI_TIMESTAMP product { CATALOG_URL LAST_UPDATE LIST_PRICE PRODUCT_DESCRIPTION PRODUCT_ID PRODUCT_NAME PRODUCT_SIZE ZZ_META_DI_TIMESTAMP } } } }